﻿/// <summary>
/// data   :2016-05-03
/// author :fanzhengyong
/// 游戏状态：资源更新
/// </summary>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace UEngine
{
    class GameStateUpdateRes : GameState
    {
        private GameObject m_loadingGo = null;
        private UpdateLoadingScript updateLoadingScript = null;
        private bool isProcessUpdate = true;
        public GameStateUpdateRes()
        {
            State = EGameState.UpdateRes;
        }

        public override void Enter()
        {
            Debug.Log("enter UpdateRes.");
            ////加载更新画面
            //GameObject UIRootGo = GameObject.FindWithTag("UIRoot");
            //if (UIRootGo == null)
            //{
            //    Debug.Log("UIRootGo == null");
            //}

            //m_loadingGo = GameObject.Instantiate(Resources.Load("UI/Image_Loading", typeof(GameObject))) as GameObject;
            //if (m_loadingGo == null)
            //{
            //    Debug.Log("loadingGo == null");
            //}

            //RectTransform UIRootTransform = UIRootGo.GetComponent<RectTransform>();
            //m_loadingGo.transform.SetParent(UIRootTransform, false);
            ////调用ResourceManager进行更新本地资源
            //m_loadingGo.AddComponent<UpdateLoadingScript>();
            //updateLoadingScript = m_loadingGo.GetComponent<UpdateLoadingScript>();\
            
            GameStateManager.Instance().ChangeState(EGameState.InitFramework);
            

            
        }

        public override void Update()
        {
            if (isProcessUpdate)
            {
                Debug.Log(updateLoadingScript.m_isFinished);
                if (updateLoadingScript.m_isFinished)
                {
                    isProcessUpdate = false;
                    GameObject.Destroy(m_loadingGo, 2.0f);
                    GameStateManager.Instance().ChangeState(EGameState.Login);
                    
                }
            }
            
        }

        public override void Exit()
        {
            Debug.Log("exit UpdateRes.");
        }
    }
}
